package com.zygh.interactiveplatform.module.mapper;

import com.zygh.interactiveplatform.module.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zygh.interactiveplatform.module.entity.vo.LoginDetailVO;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author lee
 * @since 2021-01-28
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据用户名查询用户，判断用户是否存在
     * @param username
     * @return
     */
    User findUserByUsername(String username);

    /**
     * 根据用户名查询用户权限信息
     *
     * @param username
     * @return
     */
    @Select("select u.*,r.name as roleName,d.name as deptName,r.permissions from user u " +
            "JOIN user_role r on u.role_id = r.id " +
            "JOIN dept d on u.dept_id = d.dept_id " +
            "where user_name=#{username} and status=1")
    @Results({
            @Result(property = "deptId", column = "dept_id"),
            @Result(property = "roleId", column = "role_id"),
    })
    LoginDetailVO getUserInfo(String username);

    List<User> findUserByDeptId(int id);

}
